
import 'package:flutter_menu/data/obx_store.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:objectbox/objectbox.dart';

import '../objectbox.g.dart';

part 'sellout_model.g.dart';

///估清数据
@Entity()
@JsonSerializable()
class SelloutModel with IEntity{
  @Id()
  int obxId;

  ///类型 1 菜品规格 2选项 3原料
  int? type;

  ///对应类型的id（主键）
  @Index()
  String? typeId;

  ///是否沽清 0否 1已沽清
  int? isSellout;

  double? compatSellOutCount;
  double? surplus;


  @override
  int updateTime;

  SelloutModel({this.obxId=0, this.type, this.typeId, this.isSellout, this.compatSellOutCount,
    this.surplus, this.updateTime=0});

  @override
  int update(store, int? time) {
    updateTime = time?? updateTime;
    var box =  store.box<SelloutModel>();
    return box.put(this);
  }

  factory SelloutModel.fromJson(Map<String,dynamic> json) => _$SelloutModelFromJson(json);
  Map<String, dynamic> toJson() => _$SelloutModelToJson(this);

  static ToOne<SelloutModel> toOneFromJson(Map<String, dynamic> json) =>
  ToOne(target: SelloutModel.fromJson(json));

  static Map<String, dynamic>? toOneJson(ToOne<SelloutModel> s) =>
  s.target != null ? _$SelloutModelToJson(s.target!) : {};

  static ToMany<SelloutModel> toManyFromJson(List<dynamic>? json) =>
  ToMany(items: json?.map((e) => SelloutModel.fromJson(e)).toList());

  static List<Map<String, dynamic>> toManyJson(ToMany<SelloutModel> s) =>
  s.toList().map((e) => e.toJson()).toList();
}